package wang.raye.gridviewanim;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/10/8.
 */
public class OneAdapter extends BaseAdapter implements View.OnClickListener{

    private ArrayList<String> datas;

    private LayoutInflater inflater;

    private MainActivity activity;

    public OneAdapter(Context context,ArrayList<String> datas){
        this.activity = (MainActivity) context;
        this.inflater = LayoutInflater.from(context);
        this.datas = datas;
    }
    @Override
    public int getCount() {
        if(datas != null){
            return datas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView view;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item,parent,false);
            view = (TextView) convertView.findViewById(R.id.item);
            convertView.setTag(view);
        }else{
            view = (TextView) convertView.getTag();
        }
        view.setText(datas.get(position));
        view.setId(position);
        view.setOnClickListener(this);
        return convertView;
    }

    @Override
    public void onClick(View v) {
//        int[] i = new int[2];
//        v.getLocationInWindow(i);
//        Toast.makeText(activity,"x:"+i[0]+"   y:"+i[1],Toast.LENGTH_SHORT).show();
        activity.anim((TextView) v);
    }
}
